<!DOCTYPE html>
<html lang="en">
<head>
	<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no" name="viewport">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <meta content="email=no" name="format-detection">
	<meta charset="UTF-8">
	<title></title>
	<style type="text/css">
		body{width: 100%;height: 100%;margin:0;padding:5px;min-height: 140px;}
		img{max-width: 60%;display: inline-block;}
		video{max-width: 60%;}
	</style>
	<script type="text/javascript">
		var url = /url=(.*?)$/i.exec(location.href);
		var element = document.createElement('script');
		element.setAttribute('src', url[1]+'source/plugin/jameson_read/images/jquery.min.js');
		element.setAttribute('type', 'text/javascript');
		document.getElementsByTagName('head')[0].appendChild(element);
	</script>
	<script type="text/javascript">
		function insertimg(html) {
		    document.getElementById('editbody').focus()
		    var sel, range;
		    if (window.getSelection) {
		        // IE9 and non-IE
		        sel = window.getSelection();
		        if (sel.getRangeAt && sel.rangeCount) {
		            range = sel.getRangeAt(0);
		            range.deleteContents();
		            var el = document.createElement("div");
		            el.innerHTML = html;
		            var frag = document.createDocumentFragment(),
		                node, lastNode;
		            while ((node = el.firstChild)) {
		                lastNode = frag.appendChild(node);
		            }
		            range.insertNode(frag);
		            if (lastNode) {
		                range = range.cloneRange();
		                range.setStartAfter(lastNode);
		                range.collapse(true);
		                sel.removeAllRanges();
		                sel.addRange(range);
		            }
		        }
		    } else if (document.selection && document.selection.type != "Control") {
		        document.selection.createRange().pasteHTML(html);
		    }
		}
		function updatetextarea(){
			var html = $("body").html();
			html = html.replace(/<\/?script[^>]*?>/ig,'').replace('addmedia','');
			if(/<div>/i.test(html)){
				html = html.replace(/<div>/i,'</div><div>');
				html = '<div>'+html;
				html = html.replace(/<div.*?>/ig,"<p>").replace(/<\/div>/ig,'</p>');
			}
			window.parent.postMessage(html,"*");
		}
		window.onload =function(){
			$("body").on('keyup',function(){
				updatetextarea();
			})
		};
		window.onmessage=function(e){
			var tag = e.data.replace(/\n/ig,'<br>');
			insertimg(tag);
			updatetextarea();
		};
	</script>
</head>
<body contenteditable id="editbody">
	
</body>
</html>